package com.tanhua.server.controller;

import com.tanhua.model.dto.RecommendUserDto;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    //今日佳人
    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        TodayBest vo = tanhuaService.todayBest();
        return ResponseEntity.ok(vo);
    }
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto dto){
        PageResult recommendation = tanhuaService.recommendation(dto);
        return ResponseEntity.ok(recommendation);
    }
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long userid){
        TodayBest best = tanhuaService.personalInfo(userid);
        return ResponseEntity.ok(best);
    }

    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId) {
        String questions = tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(questions);
    }

    @PostMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions (@RequestBody Map map){
        String userId = map.get("userId").toString();
        Long userid = Long.valueOf(userId);
        String reply = map.get("reply").toString();
        tanhuaService.replyQuestions(userid,reply);
        return ResponseEntity.ok(null);
    }
    @GetMapping("/cards")
    public ResponseEntity cards(){
        List<TodayBest> list = tanhuaService.queryCardsList();
        return ResponseEntity.ok(list);
    }
    @GetMapping("{id}/love")
    public ResponseEntity get(@PathVariable("id") String userid){
        boolean flag = true;
        Long value = Long.valueOf(userid);
        tanhuaService.likeuser(value,flag);
        return ResponseEntity.ok(null);
    }
    @GetMapping("{id}/unlove")
    public ResponseEntity<Void> notLikeUser(@PathVariable("id") Long likeUserId) {
        boolean flag = false;
        this.tanhuaService.likeuser(likeUserId,flag);
        return ResponseEntity.ok(null);
    }

    @GetMapping("/search")
    public ResponseEntity search( String gender,@RequestParam(defaultValue = "2000") String distance){
        List<NearUserVo> list = tanhuaService.nearuser(gender,distance);
        return ResponseEntity.ok(list);
    }
}